package com.niit.demo05;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

public class checkedBox extends AppCompatActivity {
    TextView result;
    CheckBox english,math,Android,data;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_checked_box);
        result = findViewById(R.id.result);
        english=findViewById(R.id.ck_english);
        math=findViewById(R.id.ck_math);
        Android=findViewById(R.id.ck_Android);
        data=findViewById(R.id.ck_data);

        CheckedChanged checkedChanged=new CheckedChanged();
        english.setOnCheckedChangeListener(checkedChanged);
        math.setOnCheckedChangeListener(checkedChanged);
        Android.setOnCheckedChangeListener(checkedChanged);
        data.setOnCheckedChangeListener(checkedChanged);
    }
    class CheckedChanged implements CompoundButton.OnCheckedChangeListener{
        String course;
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked){
            course="";
            result.setText("");
            if(english.isChecked()){
                //        course=course+""+english.getText().toString();
                course = english.getText().toString();
            }
            if(math.isChecked()){
                course+=" "+math.getText().toString();
            }
            if(Android.isChecked()){
                course+=" "+Android.getText().toString();
            }
            if(data.isChecked()){
                course+=" "+data.getText().toString();
            }
            result.setText(course);
        }
    }
}
